# -*- coding: utf-8 -*-
import time, functools

# Decorator 装饰器
def metric(fn):
    @functools.wraps(fn)
    def wrapper(*args, **kw):
        start_time = time.time()
        fn(*args, **kw)     # args 为元组 *arg 即字典的序列解包 kw 为字典 **kw 为字典的序列解包
        end_time = time.time()
        print('%s executed in %s ms' % (fn.__name__, end_time - start_time))
        return fn(*args, **kw) # 返回fn函数执行结果
    return wrapper


@metric # @metric 为 fast = metric(fast)
def fast(x, y):
    time.sleep(0.0012)
    return x + y

@metric
def slow(x, y, z):
    time.sleep(0.1234)
    return x * y * z

f = fast(11, 22)
s = slow(11, 22, 33)
print(f)
if f != 33:
    print('测试失败!')
elif s != 7986:
    print('测试失败!')
